﻿using CommonCache.Extensions.Abstract;
using StackExchange.Redis;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonCache.Extensions.Implementation
{
    public class RedisCacheSource : ICacheSource
    {
        private Lazy<ConnectionMultiplexer> LazyConnection;

        private ConnectionMultiplexer Connection => LazyConnection.Value;

        //private ConcurrentDictionary<int, IDatabase> DataBases = new ConcurrentDictionary<int, IDatabase>();

        public ConfigurationOptions ConfigInfo { get; private set; }

        public IDatabase this[int index] => Connection.GetDatabase(index);

        public RedisCacheSource(string serverInfo)
        {
            ConfigInfo = ConfigurationOptions.Parse(serverInfo);
            LazyConnection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(ConfigInfo));

        }

        public T Get<T>(string key, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }

        public Task<T> GetAsync<T>(string key, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }

        public void Set<T>(string key, TimeSpan? time, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }

        public Task SetAsync<T>(string key, TimeSpan? time, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }

        public T HashGet<T>(string key, string field, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }

        public Task<T> HashGetAsync<T>(string key, string field, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }

        public void HashSet<T>(string key, IDictionary<string, T> kvs, TimeSpan? time, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }

        public Task HashSetAsync<T>(string key, IDictionary<string, T> kvs, TimeSpan? time, int dbIndex = 0)
        {
            throw new NotImplementedException();
        }


        //public async Task<bool> ConnectAsync()
        //{
        //}

        //public Task<bool> DisconnectAsync()
        //{
        //    throw new NotImplementedException();
        //}
    }
}